package com.jc.subject.domin.handler.subject;

import com.jc.subject.common.enums.IsDeletedFlagEnum;
import com.jc.subject.common.enums.SubjectInfoTypeEnum;
import com.jc.subject.domin.convert.SubjectBriefConverter;
import com.jc.subject.domin.convert.SubjectJudgeConverter;
import com.jc.subject.domin.entity.SubjectInfoBO;
import com.jc.subject.domin.entity.SubjectOptionBO;
import com.jc.subject.infra.basic.entity.SubjectBrief;
import com.jc.subject.infra.basic.entity.SubjectJudge;
import com.jc.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;

/**
 * @Description: 简答题目的策略类
 * @Author: ASL_ly
 * @Package: com.jc.subject.domin.handler.subject
 * @Project: jc-club
 * @Date: 2024/10/23  20:39
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler{
    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBrief.setSubjectAnswer(subjectInfoBO.getSubjectAnswer());
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.code);

        subjectBriefService.Insert(subjectBrief);
    }

    @Override
    public SubjectOptionBO query(Long subjectId) {
        SubjectBrief subjectBrief= SubjectBrief.builder()
                .subjectId(subjectId)
                .isDeleted(IsDeletedFlagEnum.UN_DELETED.code)
                .build();
        SubjectBrief result = subjectBriefService.queryByCondition(subjectBrief).get(0);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBO;
    }
}
